package org.grayrabbit.cms.publish.api;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import net.sf.json.JSONObject;

public class PublishInfo implements Serializable {
	private static final long serialVersionUID = 7239668071058729245L;
	private String publishKey;
	private String publishTaskName;
	private int successNum;
	private boolean over;
	private int failureNum;
	private int percent;
	private int total;
	
	private List<LogInfo> loginfos = new ArrayList<PublishInfo.LogInfo>();
	/**表示当前任务是否已结束*/
	public boolean isOver() {
		return over;
	}

	public void setOver(boolean over) {
		this.over = over;
	}

	/**当前成功总数*/
	public int getSuccessNum() {
		return successNum;
	}

	public void setSuccessNum(int successNum) {
		this.successNum = successNum;
	}

	/**当前失败总数*/
	public int getFailureNum() {
		return failureNum;
	}

	public void setFailureNum(int failureNum) {
		this.failureNum = failureNum;
	}
	
	public String getPublishKey() {
		return publishKey;
	}

	public void setPublishKey(String publishKey) {
		this.publishKey = publishKey;
	}
	/**当前所有百分数*/
	public int getPercent() {
		return percent;
	}

	public void setPercent(int percent) {
		this.percent = percent;
	}

	
	public String getPublishTaskName() {
		return publishTaskName;
	}

	public void setPublishTaskName(String publishTaskName) {
		this.publishTaskName = publishTaskName;
	}
	
	/**任务总数*/
	public int getTotal() {
		return total;
	}

	public void setTotal(int total) {
		this.total = total;
	}

	/**
	 * 增加生成日志
	 * @param logInfo 日志信息
	 * @param finished 当前操作(生成静态页)是否完成
	 * @param time		当前操作(生成静态)的启动时间
	 */
	public void addLogInfo(String logInfo,boolean finished,Date time, boolean error){
		loginfos.add(new LogInfo(logInfo,finished,time,error));
	}
	
	
	public List<LogInfo> getLoginfos() {
		return loginfos;
	}

	public String toJson(){
		JSONObject  obj = JSONObject.fromObject(this);
		return obj.toString();
	}
	public class LogInfo implements Serializable{
		private static final long serialVersionUID = 6918071999111177944L;
		private Date time;
		private String logInfo;
		private boolean finished = false;
		private boolean error = false;
		public LogInfo(String logInfo,boolean finished,Date time, boolean error){
			this.time = time;
			this.logInfo = logInfo;
			this.finished = finished;
			this.error = error;
		}
		
		public Date getTime() {
			return time;
		}

		public void setTime(Date time) {
			this.time = time;
		}

		public String getLogInfo() {
			return logInfo;
		}
		public void setLogInfo(String logInfo) {
			this.logInfo = logInfo;
		}
		public boolean isFinished() {
			return finished;
		}
		public void setFinished(boolean finished) {
			this.finished = finished;
		}
		public boolean isError() {
			return error;
		}
		public void setError(boolean error) {
			this.error = error;
		}
		
	}
}
